package com.hzhr.iot.device.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.controller.base.BaseController;
import com.hzhr.iot.device.model.regulatorDevice_monitor_collectData.RegulatorDevice_Monitor_CollectDataGetModel;
import com.hzhr.iot.device.model.regulatorDevice_monitor_commandSend.RegulatorDevice_Monitor_CommandSendGetModel;
import com.hzhr.iot.device.model.regulatorDevice_monitor_commandSend.RegulatorDevice_Monitor_CommandSendPostModel;
import com.hzhr.iot.device.service.RegulatorDevice_Monitor_CollectDataService;
import com.hzhr.iot.device.service.RegulatorDevice_Monitor_CommandSendService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "RegulatorDevice_Monitor_CommandSend", description = "调压设备下的监控设备的指令推送")
@RestController
@RequestMapping(value = "")
public class RegulatorDevice_Monitor_CommandSendController extends BaseController {
    @Autowired
    RegulatorDevice_Monitor_CommandSendService regulatorDevice_monitor_commandSendService;

    //region /regulator-devices/{regulatorDeviceId}/monitors/{monitorId}/command-sends POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询调压设备  \n----异常说明 : 调压设备不存在  \n\n----异常代码 : 202  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询监控设备  \n----异常说明 : 监控设备不存在  \n\n----异常代码 : 203  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证监控设备是否具备发送目标指令的条件  \n----异常说明 : 该监控设备无法进行此操作  \n\n----异常代码 : 204  \n----异常类型 : 业务流程异常  \n----异常业务 : 发送指令  \n----异常说明 : 指令下发异常  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="查询调压设备下的监控设备", notes="查询调压设备下的监控设备  \n步骤 :  \n1. 查询调压设备 : 查询调压设备，如果不存在则抛出异常“调压设备不存在”  \n2. 查询监控设备：查询该调压设备下的监控设备，如果监控设备不存在，抛出异常“监控设备不存在”  \n3. 验证监控设备是否具备发送目标指令的条件 ：  \n (1) 如果指令类型为1(开阀)或2(开阀)，只有DTU才能够发送  \n 如果监控设备不具备发送目标指令的条件，抛出异常“该监控设备无法进行此操作”  \n4. 发送指令：  \n (1) 如果指令类型为1(开阀)或2(开阀)，通过迅腾平台向设备推送指令。如果没有收到成功下发的响应，则抛出异常“指令下发异常”，并记录日志  \n5. 返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "regulatorDeviceId", value = "调压设备编号",required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "monitorId", value = "监控设备编号",required = true, dataType = "int", paramType = "path"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/regulator-devices/{regulatorDeviceId}/monitors/{monitorId}/command-sends", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<RegulatorDevice_Monitor_CommandSendGetModel> post(@PathVariable("regulatorDeviceId")Integer regulatorDeviceId,
                                                                            @PathVariable("monitorId")Integer monitorId,
                                                                            @RequestParam @ApiIgnore Map<String, Object> query,
                                                                            @RequestBody RegulatorDevice_Monitor_CommandSendPostModel body) throws ServiceException {
        RegulatorDevice_Monitor_CommandSendGetModel responseBody = regulatorDevice_monitor_commandSendService.post(initHeader(), regulatorDeviceId,monitorId,query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion

}



































































































































































